<template>
  <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    background-color="#545c6400"
    text-color="#606266"
    active-text-color="#409EFF"
    unique-opened
    router
    style="background-color: #E4E7ED;"
  >
    <sub-menu
      v-for="menuitem in menuList"
      :key="menuitem.pid"
      :menuitem="menuitem"
      :index="menuitem.id"
    ></sub-menu>
    <el-menu-item @click="goShow" style="color: #606266;">返回首页</el-menu-item>
     <el-menu-item @click="logout" style="color: #606266;">安全退出</el-menu-item>
  </el-menu>
</template>
<script>
import SubMenu from "./SubMenu.vue";
import { getMenus,exit } from "@/api/MainMenu.js";
import{userLoginout} from"../api/login"
export default {
  data() {
    return {
      menuList: [],
    };
  },
  components: {
    SubMenu,
  },
  methods: {
    logout() {
       userLoginout().then((res) => {
        if (res.data.code == 200) {
          this.$message.success(res.data.msg)
          sessionStorage.removeItem("token");
          this.$router.push("/");
        }
      });
    },
    goShow() {
      this.$router.push("/Home/Show");
    },
    getMenus() {
      getMenus().then((res) => {
        if (res.data.code == 200) {
          this.menuList = res.data.data;

        }
      });
    },
    handleOpen() {},
    handleClose() {},
  },
  mounted() {
    this.getMenus();
  },
};
</script>
